<?php

declare(strict_types=1);

namespace app\api\controller;

use app\common\tool\Result;
use app\common\controller\Config;
use think\facade\View;
use think\Response;
use app\common\model\Remit as RemitModel;
use think\exception\ValidateException;

class Remit extends Base
{
    /**
     * 充值参数
     */
    public function remitInfo()
    {
        try {
            $data['money'] = $this->user->assets->bonus_1;
            $list = [
                [
                    'title' => 'USDT_BSC20',
                    'img' => Config::lists()['usdt_erc20_qrcode'],
                    'url' => Config::lists()['usdt_erc20_url'],
                    'type' => 'USDT_BSC20',
                ],
                [
                    'title' => 'USDT_BEP20',
                    'img' => Config::lists()['usdt_trc20_qrcode'],
                    'url' => Config::lists()['usdt_trc20_url'],
                    'type' => 'USDT_BEP20',
                ]

            ];
            $data['list']=$list;
            return Result::success('获取成功！', $data);
        } catch (\Exception $e) {
            return Result::fail($e->getMessage());
        }
    }
    /**
     * 充值记录
     */
    public function getList(): Response
    {
        $param = $this->request->param();
        try {
            $map = ['uid' => $this->user->id];
            return Result::fastReturn(RemitModel::getPageList($map, 'id,pay_way,create_time,status,amount', $param['page'], 20, false));
        } catch (\Exception $e) {
            return Result::fail($e->getMessage());
        }
    }
    /**
     * 充值提交
     */
    public function save(): Response
    {
        $param = $this->request->post();
        try {
            $this->validate($param, 'Remit');
            return Result::fastReturn(RemitModel::add($param, $this->user, Config::lists()));
        } catch (ValidateException $e) {
            return Result::fail($e->getError());
        }
    }
}
